package com.ai.core.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DataFormat {
       public String dataFormat(Date date){
    	   String showDate = new java.text.SimpleDateFormat("yyyy-mm-dd HH:mm:ss").format(date);
    	   return showDate;
       }
       
       
       public static String getCHNDate(Date date){
      	 SimpleDateFormat hourFormat = new SimpleDateFormat("HH:mm");
  	        SimpleDateFormat monthFormat = new SimpleDateFormat("MM月dd日 #HH:mm");
  	        SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy年MM月dd日");

  	        Calendar todayCalendar = Calendar.getInstance();
  	        todayCalendar.setTime(new Date());
  	        todayCalendar.add(Calendar.DATE, 1); //日期加1天   
  	        todayCalendar.set(Calendar.HOUR_OF_DAY, 0);
  	        todayCalendar.set(Calendar.SECOND,0);
  	        todayCalendar.set(Calendar.MINUTE,0); 

  	        Calendar dateCalendar = Calendar.getInstance();
  	        dateCalendar.setTime(date);
  	        int ap = dateCalendar.get(GregorianCalendar.AM_PM);
  	        String replaceStr = ap == 0 ? "上午":"下午";
  		 
  	        long between=todayCalendar.getTime().getTime()-date.getTime();//除以1000是为了转换成秒
  	        String msg;
  	        if(between > 86401000L && between <= 86401000L*2){
  	        	msg="昨天 #"+hourFormat.format(date);
  	        }else  if(between <= 86401000L){
  	        	msg = "#"+hourFormat.format(date);
  	        }else if(between > 31556925960L){
  	        	msg  = yearFormat.format(date);
  	        }else{
  	        	msg=monthFormat.format(date);
  	        }
  	        
  	        msg = msg.replace("#", replaceStr);
  	        return msg;
      }
}
